<?php

namespace app\modules\group\models;

use app\common\base\CommonModel;
use yii\helpers\ArrayHelper;
use app\modules\user\behaviors\AccountBehavior;

class GroupUser extends CommonModel
{
    // 数据库表名设置
    public static function tableName()
    {
        return '{{%group_user}}';
    }

    /**
     * rules
     *
     * @return array
     */
    public function rules()
    {
        return [
            [['groupId', 'userId'],'required'],
            [['groupId', 'userId'], 'integer'],
            [['join_timestamp'], 'integer']
        ];
    }


    public function behaviors()
    {
        return parent::behaviors();
    }

    /**
     * beforeSave
     *
     * @param bool $insert
     * @return void
     */
    public function beforeSave($insert)
    {
        if ($insert) {
            // $this->status = 1;
        }

        return parent::beforeSave($insert);
    }


    public function fields(){
        $fields = parent::fields();
        
        //创建时间戳
        if(isset($fields['join_timestamp'])){
            $fields['join_time'] = function($model){
                return date("Y-m-d H:i", $model->join_timestamp/1000);
            };
        }
        return $fields;
    }

}

